//
// InterfaceCallbackStream.cpp for InterfaceCallbackStream in /home/mambou_j//babel-2014/babel-2014/Portaudio
// 
// Made by jacquesquentin mamboumouafo
// Login   <mambou_j@epitech.net>
// 
// Started on  Tue May 15 20:01:54 2012 jacquesquentin mamboumouafo
// Last update Tue May 15 20:20:57 2012 jacquesquentin mamboumouafo
//


#include	"InterfaceCallbackStream.hpp"
#include	"StreamParameters.hpp"
#include	"Exception.hpp"
#include	"CallbackInterface.hpp"

namespace	portaudio
{

  InterfaceCallbackStream::InterfaceCallbackStream()
  {
  }

  InterfaceCallbackStream::InterfaceCallbackStream(const StreamParameters &parameters, CallbackInterface &instance)
  {
    open(parameters, instance);
  }

  InterfaceCallbackStream::~InterfaceCallbackStream()
  {
	try
	  {
	    close();
	  }
	catch (...)
	  {
	  }
  }

  void	InterfaceCallbackStream::open(const StreamParameters &parameters, CallbackInterface &instance)
  {
    PaError	err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(), parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::callbackInterfaceToPaCallbackAdapter, static_cast<void *>(&instance));

    if (err != paNoError)
      {
	throw PaException(err);
      }
  }
}
